﻿using System.Windows.Forms;

namespace QuailRepositoryManager
{
    /// <summary>
    /// Nice little class to show the WaitCursor
    /// </summary>
    public class WaitCursor
    {
        private readonly Cursor _oldCur;
        private bool _restored;

        /// <summary>
        /// Initializes a new instance of the <see cref="WaitCursor"/> class.
        /// </summary>
        public WaitCursor()
        {
            _oldCur = Cursor.Current;
            Cursor.Current = Cursors.WaitCursor;
        }

        ~WaitCursor()
        {
            Restore();
        }

        /// <summary>
        /// Restores the cursor to the previous cursor
        /// </summary>
        public void Restore()
        {
            if (!_restored)
            {
                _restored = true;
                Cursor.Current = _oldCur;
            }
        }
    }
}
